package com.msg.controller;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.msg.core.result.Result;
import com.msg.domain.dto.QuestionAppealDTO;
import com.msg.domain.model.XxtOfficer;
import com.msg.domain.model.XxtTown;
import com.msg.service.QuestionSevice;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequiredArgsConstructor
public class QuestionController {

    private final QuestionSevice questionSevice;
    /**
     * 上诉
     * @param appealDTO
     * @return
     * @throws Exception
     */
    @PostMapping("/question/appeal")
    public Result<?> appeal(@RequestBody @Valid QuestionAppealDTO appealDTO){
        questionSevice.appeal(appealDTO);
        return Result.success();
    }

    /**
     * 村镇列表
     * @return
     * @throws Exception
     */
    @GetMapping("/town/select")
    public Result<?> townSelect(){
        List<XxtTown> list= questionSevice.townSelect();
        return Result.success(list);
    }


    /**
     * 干部列表
     * @return
     * @throws Exception
     */
    @GetMapping("/officer/select")
    public Result<?> officerSelect(){
        List<XxtOfficer> list=questionSevice.officerSelect();
        return Result.success(list);
    }

    /**
     * 干部列表
     * @return
     * @throws Exception
     */
    @GetMapping("/officer/qrcode")
    public Result<?> officerQrcode(String objectType){
        if(StrUtil.isBlank(objectType)){
            return Result.error("objectType不能为空");
        }
        String url=questionSevice.officerQrcode(objectType);
        return Result.success(MapUtil.builder().put("url",url).build());
    }
}
